package com.ews.onlineexchange.service;

import java.io.Serializable;

import javax.inject.Inject;
import javax.inject.Named;

import com.ews.onlineexchange.exception.EmailException;
import com.ews.onlineexchange.model.ShortMessage;
import com.ews.onlineexchange.util.Config;
import com.ews.onlineexchange.util.PropertiesUtil;

@Named
public class EmailService implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Inject
	Config config;
	
	
	public void sendFailNotification(ShortMessage shortMessage) {
		try {
			PropertiesUtil util = new PropertiesUtil("/config.properties");
			EmailSender emailSender = new EmailSender();
			String admins = util.getProperty("com.ews.onlineExchange.email.adminEmail");
			String[] addresses = admins.split(",");
			for (int i = 0; i < addresses.length; i++) {
				emailSender.send(addresses[i], "短信发送失败提醒", "", shortMessage.getContent());
			}
			
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
	
	public void sendFailNotification(String content) {
		try {
			PropertiesUtil util = new PropertiesUtil("/config.properties");
			EmailSender emailSender = new EmailSender();
			String admins = util.getProperty("com.ews.onlineExchange.email.adminEmail");
			String[] addresses = admins.split(",");
			for (int i = 0; i < addresses.length; i++) {
				emailSender.send_1(addresses[i], "短信发送失败提醒", "", content);
			}
			
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		EmailService service = new EmailService();
		service.sendFailNotification("小可爱");
		
	}
}
